package net.jam.UI;

import java.applet.Applet;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingConstants;
import javax.swing.WindowConstants;


import net.jam.loader.*;




/**
 * @author Drew
 */
public class UI extends JFrame {
	public UI() {
		initComponents();
	}

	private void QuitActionPerformed(ActionEvent e) {
		this.dispose();
	}

	private void LoadRSActionPerformed(ActionEvent e) throws Exception {
		ParamLoader p = new ParamLoader("world1");
		p.loadParams();
		Class<?> clientClass = null;
		RSLoader rsLoader = new RSLoader();
		clientClass = rsLoader.loadClass("client");
		assert clientClass != null;
		Applet loader = (Applet) clientClass.newInstance();
		ClientStub clientStub = new ClientStub("http://world1.runescape.com", "http://world1.runescape.com/m0", p.params());
		loader.setStub(clientStub);
		loader.init();
		loader.start();
		scrollPane1.setViewportView(loader);
		
	}

	private void UserInputActionPerformed(ActionEvent e) {
		// TODO add your code here
	}

	private void StartScriptActionPerformed(ActionEvent e) {
		// TODO add your code here
	}

	private void StopScriptPerformed(ActionEvent e) {
		// TODO add your code here
	}

	private void PauseScriptActionPerformed(ActionEvent e) {
		// TODO add your code here
	}

	private void AccountsActionPerformed(ActionEvent e) {
		// TODO add your code here
	}

	private void ViewConsoleActionPerformed(ActionEvent e) {
		if (checkBoxMenuItem2.isSelected()) {
			setSize(768, 555);
		} else {
			setSize(768, 680);
		}
	}

	private void AboutActionPerformed(ActionEvent e) {
		// TODO add your code here
	}

	private void initComponents() {
		// JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
		menuBar1 = new JMenuBar();
		menu1 = new JMenu();
		menuItem1 = new JMenuItem();
		menu2 = new JMenu();
		menuItem2 = new JMenuItem();
		checkBoxMenuItem1 = new JCheckBoxMenuItem();
		menu5 = new JMenu();
		menuItem8 = new JMenuItem();
		menuItem9 = new JMenuItem();
		checkBoxMenuItem3 = new JCheckBoxMenuItem();
		menuItem6 = new JMenuItem();
		menu3 = new JMenu();
		checkBoxMenuItem2 = new JCheckBoxMenuItem();
		menu4 = new JMenu();
		menuItem7 = new JMenuItem();
		scrollPane1 = new JScrollPane();
		scrollPane2 = new JScrollPane();
		textArea1 = new JTextArea();
		JPopupMenu.setDefaultLightWeightPopupEnabled(false);

		//======== this ========
		setTitle("JamBot Alpha");
		setResizable(false);
		setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		setIconImage(new ImageIcon("/home/matty/Documents/workspace/JAMBot/resources/jam.jpg").getImage());
		Container contentPane = getContentPane();
		contentPane.setLayout(null);

		//======== menuBar1 ========
		{

			//======== menu1 ========
			{
				menu1.setText("File");

				//---- menuItem1 ----
				menuItem1.setText("Quit");
				menuItem1.setHorizontalAlignment(SwingConstants.TRAILING);
				menuItem1.addActionListener(new ActionListener() {
					@Override
					public void actionPerformed(ActionEvent e) {
						QuitActionPerformed(e);
					}
				});
				menu1.add(menuItem1);
			}
			menuBar1.add(menu1);

			//======== menu2 ========
			{
				menu2.setText("Bot");

				//---- menuItem2 ----
				menuItem2.setText("Load");
				menuItem2.addActionListener(new ActionListener() {
					@Override
					public void actionPerformed(ActionEvent e) {
						try {
							LoadRSActionPerformed(e);
						} catch (Exception e1) {
							e1.printStackTrace();
						}
					}
				});
				menu2.add(menuItem2);

				//---- checkBoxMenuItem1 ----
				checkBoxMenuItem1.setText("User Input");
				checkBoxMenuItem1.addActionListener(new ActionListener() {
					@Override
					public void actionPerformed(ActionEvent e) {
						UserInputActionPerformed(e);
					}
				});
				menu2.add(checkBoxMenuItem1);
				menu2.addSeparator();

				//======== menu5 ========
				{
					menu5.setText("Script");

					//---- menuItem8 ----
					menuItem8.setText("Start Script");
					menuItem8.addActionListener(new ActionListener() {
						@Override
						public void actionPerformed(ActionEvent e) {
							StartScriptActionPerformed(e);
						}
					});
					menu5.add(menuItem8);

					//---- menuItem9 ----
					menuItem9.setText("Stop Script");
					menuItem9.addActionListener(new ActionListener() {
						@Override
						public void actionPerformed(ActionEvent e) {
							StopScriptPerformed(e);
						}
					});
					menu5.add(menuItem9);

					//---- checkBoxMenuItem3 ----
					checkBoxMenuItem3.setText("Pause Script");
					checkBoxMenuItem3.addActionListener(new ActionListener() {
						@Override
						public void actionPerformed(ActionEvent e) {
							PauseScriptActionPerformed(e);
						}
					});
					menu5.add(checkBoxMenuItem3);
				}
				menu2.add(menu5);
				menu2.addSeparator();

				//---- menuItem6 ----
				menuItem6.setText("Accounts");
				menuItem6.addActionListener(new ActionListener() {
					@Override
					public void actionPerformed(ActionEvent e) {
						AccountsActionPerformed(e);
					}
				});
				menu2.add(menuItem6);
			}
			menuBar1.add(menu2);

			//======== menu3 ========
			{
				menu3.setText("Debug");

				//---- checkBoxMenuItem2 ----
				checkBoxMenuItem2.setText("View Console");
				checkBoxMenuItem2.addActionListener(new ActionListener() {
					@Override
					public void actionPerformed(ActionEvent e) {
						ViewConsoleActionPerformed(e);
					}
				});
				menu3.add(checkBoxMenuItem2);
			}
			menuBar1.add(menu3);

			//======== menu4 ========
			{
				menu4.setText("Help");

				//---- menuItem7 ----
				menuItem7.setText("About");
				menuItem7.addActionListener(new ActionListener() {
					@Override
					public void actionPerformed(ActionEvent e) {
						AboutActionPerformed(e);
					}
				});
				menu4.add(menuItem7);
			}
			menuBar1.add(menu4);
		}
		setJMenuBar(menuBar1);
		contentPane.add(scrollPane1);
		scrollPane1.setBounds(0, 0, 765, 505);

		//======== scrollPane2 ========
		{
			scrollPane2.setViewportView(textArea1);
		}
		contentPane.add(scrollPane2);
		scrollPane2.setBounds(0, 505, 765, 125);

		contentPane.setPreferredSize(new Dimension(770, 680));
		setSize(768, 680);
		setLocationRelativeTo(getOwner());
		// JFormDesigner - End of component initialization  //GEN-END:initComponents
	}

	// JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
	private JMenuBar menuBar1;
	private JMenu menu1;
	private JMenuItem menuItem1;
	private JMenu menu2;
	private JMenuItem menuItem2;
	private JCheckBoxMenuItem checkBoxMenuItem1;
	private JMenu menu5;
	private JMenuItem menuItem8;
	private JMenuItem menuItem9;
	private JCheckBoxMenuItem checkBoxMenuItem3;
	private JMenuItem menuItem6;
	private JMenu menu3;
	private JCheckBoxMenuItem checkBoxMenuItem2;
	private JMenu menu4;
	private JMenuItem menuItem7;
	private JScrollPane scrollPane1;
	private JScrollPane scrollPane2;
	private JTextArea textArea1;
	// JFormDesigner - End of variables declaration  //GEN-END:variables
}
